
#include <iostream>
using namespace   std;

void TestBasicSizeOf()
{
    cout << __FUNCTION__ << endl;

    cout << "  sizeof(char)= " << sizeof ( char ) << endl;
    cout << "  sizeof(int)= " << sizeof ( int ) << endl;
    cout << "  sizeof(float)= " << sizeof ( float ) << endl;
    cout << "  sizeof(double)= " << sizeof ( double ) << endl;

    cout << "  sizeof('$')=" << sizeof ( '$' ) << endl;
    cout << "  sizeof(1)= " << sizeof ( 1 ) << endl;
    cout << "  sizeof(1.5f)= " << sizeof ( 1.5f ) << endl;
    cout << "  sizeof(1.5)= " << sizeof ( 1.5 ) << endl;

    cout << "  sizeof(Good!)= " << sizeof ( "Good!" ) << endl ;

    char  str[] = "CharArray!";
    int  a[10]; 
    double  xy[10];
    cout << "  char str[] = \"CharArray!\"," << " sizeof(str)= " << sizeof (str) << endl;
    cout << "  int a[10]," << " sizeof(a)= " << sizeof (a) << endl;
    cout << "  double xy[10]," << " sizeof(xy)= " <<   sizeof (xy) << endl;

    cout << "  sizeof(void*)= " << sizeof(void*) << endl;
}

struct st1
{
    short number;
    float math_grade;
    float Chinese_grade;
    float sum_grade;
    char  level;
}; // 20

struct st2
{
    char  level;
    short number;
    float math_grade;
    float Chinese_grade;
    float sum_grade;
}; // 16

#pragma pack(1)
struct st3
{
    char  level;
    short number;
    float math_grade;
    float Chinese_grade;
    float sum_grade;
}; // 15
#pragma pack() 

void TestStructSizeOf()
{
    cout << __FUNCTION__ << endl;

    cout << "  sizeof(st1)= " << sizeof (st1) << endl;
    cout << "  offsetof(st1,number) " << offsetof(st1,number) << endl;
    cout << "  offsetof(st1,math_grade) " << offsetof(st1,math_grade) << endl;
    cout << "  offsetof(st1,Chinese_grade) " << offsetof(st1,Chinese_grade) << endl;
    cout << "  offsetof(st1,sum_grade) " << offsetof(st1,sum_grade) << endl;
    cout << "  offsetof(st1,level) " << offsetof(st1,level) << endl;

    cout << "  sizeof(st2)= " << sizeof (st2) << endl;
    cout << "  offsetof(st2,level) " << offsetof(st2,level) << endl;
    cout << "  offsetof(st2,number) " << offsetof(st2,number) << endl;
    cout << "  offsetof(st2,math_grade) " << offsetof(st2,math_grade) << endl;
    cout << "  offsetof(st2,Chinese_grade) " << offsetof(st2,Chinese_grade) << endl;
    cout << "  offsetof(st2,sum_grade) " << offsetof(st2,sum_grade) << endl;


    cout << "  sizeof(st3)= " << sizeof (st3) << endl;
    cout << "  offsetof(st3,level) " << offsetof(st3,level) << endl;
    cout << "  offsetof(st3,number) " << offsetof(st3,number) << endl;
    cout << "  offsetof(st3,math_grade) " << offsetof(st3,math_grade) << endl;
    cout << "  offsetof(st3,Chinese_grade) " << offsetof(st3,Chinese_grade) << endl;
    cout << "  offsetof(st3,sum_grade) " << offsetof(st3,sum_grade) << endl;
}

struct A
{
	int i;
	char c;
	double d;
	short s;
}; // 24

struct B
{
	char cc;
	A a;
	int ii;
}; // 40

#pragma pack(4)
struct A2
{
	int i;
	char c;
	double d;
	short s;
}; // 20
#pragma pack()

struct B2
{
	char cc;
	A2 a;
	int ii;
}; // 28

struct empty{}; // 1
struct constAndStatic
{
    const int i;
    static char c;
    const double d;
    static void TestStatic(){}
    void TestNoStatic(){}
}; // 16